package com.example.controller;

import com.example.pojo.Author;
import com.example.pojo.AuthorQueryParam;
import com.example.pojo.PageResult;
import com.example.pojo.Result;
import com.example.service.AuthorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/authors")
public class AuthorController {
    @Autowired
    private AuthorService authorService;

    @GetMapping
    public Result page(AuthorQueryParam authorQueryParam){
        log.info("分页查询 {}" , authorQueryParam);
        PageResult<Author> pageResult= authorService.page(authorQueryParam);
        return Result.success(pageResult);
    }
    @PostMapping
    public Result save(@RequestBody Author author){
        log.info("新增员工{}",author);
        authorService.save(author);

        return Result.success();
    }
    @DeleteMapping
    public Result delete(@RequestParam List <Integer> ids) {
        log.info("删除员工{}", ids);
        authorService.delete(ids);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getById(@PathVariable  Integer id){
        log.info("根据ID查询员工{}",id);
        Author author= authorService.getInfo(id);
        return Result.success(author);
    }
    @PutMapping
    public Result update(@RequestBody Author author){
        log.info("修改员工信息{}",author);
        authorService.update(author);
        return Result.success();
    }
    @GetMapping("/list")
    public Result show(){
        log.info("查询班主任");
        List<Author> list= authorService.showByauthor();
        return Result.success(list);
    }

}
